package com.ruoyi.expertmodel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.expertmodel.domain.LoadModel;
import com.ruoyi.expertmodel.domain.LoadModel;
import com.ruoyi.expertmodel.mapper.LoadModelMapper;
import com.ruoyi.expertmodel.service.LoadModelService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LoadModelServiceImpl  extends ServiceImpl<LoadModelMapper, LoadModel> implements LoadModelService {

    @Resource
    private LoadModelMapper loadModelMapper;

    @Override
    public List<LoadModel> queryLoadModel(LoadModel loadModel) {
        return loadModelMapper.queryLoadModel(loadModel);
    }

    @Override
    public boolean deleteLoadModel(LoadModel loadModel) {
        return loadModelMapper.deleteLoadModel(loadModel.getId())>0;
    }

    @Transactional
    @Override
    public boolean batchImport(List<LoadModel> LoadModels) {
        boolean flag = true;
        for(LoadModel e :LoadModels){
            try{
                boolean save = this.save(e);

                if(!save){
                    flag=false;
                }
            }catch (Exception e1){
                flag = false;

            }

        }
        return flag;
    }

    @Override
    public void copyLoadModel(LoadModel loadModel) {
        loadModelMapper.insert(loadModel);
    }
}
